import '../core/logger.dart';
import 'hi_http_method.dart';

abstract class HiBaseRequest {
  var pathParams;
  var useHttps = true;

  String authority();

  HttpMethod httpMethod();

  bool needLogin();

  String path();

  String url() {
    Uri uri;
    var pathStr = path();
    //拼接path参数
    if (pathParams != null) {
      if (path().endsWith("/")) {
        pathStr = "${path()}$pathParams";
      } else {
        pathStr = "${path()}/$pathParams";
      }
    }

    //http 和 https 切换
    if (useHttps) {
      uri = Uri.https(authority(), pathStr, params);
    } else {
      uri = Uri.http(authority(), pathStr, params);
    }

    logger.i("url:${uri.toString()}");

    return uri.toString();
  }

  Map<String, String> params = {};

  ///添加参数
  HiBaseRequest add(String key, dynamic value) {
    params[key] = value.toString();
    return this;
  }

  Map<String, dynamic> get header => {};

  /// 添加header
  HiBaseRequest addHeader(String key, dynamic value) {
    header[key] = value.toString();
    return this;
  }
}
